/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    queue<TreeNode*> cur;
    vector<int> array;
    vector<int> levelOrder(TreeNode* root) {
        if(array.size()) array.clear();
        if(root) cur.push(root);
        while(cur.size()){
            int cursize=cur.size();
            for(int i=0;i<cursize;i++){
                TreeNode* newNode=cur.front();
                if(newNode->left) cur.push(newNode->left);
                if(newNode->right) cur.push(newNode->right);
                array.push_back(newNode->val);
                cur.pop();
            }
            
        }
        return array;
    }
};